﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using V5_Common;
using V5_BLL;
using V5_Model;

namespace V5_EShop.Admin
{
    public partial class Admin_ProductOrder : BasicPage
    {
        const string vProductOrder = "vProductOrder";
        public ModelProductOrder m_productorder = new ModelProductOrder();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                Action = Input.SetString(Request["Action"]);
                int OrderID = Input.SetInt(Request["OrderID"]);
                switch (Action)
                {
                    case "edit":
                        this.MultiViewList.ActiveViewIndex = 1;
                        if (OrderID > 0)
                        {
                            Bind_View(OrderID);
                        }
                        break;
                    default:
                        this.Bind_gvList();
                        break;
                }
            }
        }

        private void Bind_gvList()
        {
            this.MultiViewList.ActiveViewIndex = 0;
            string strWhere = "";
            if (ViewState[vProductOrder] != null && Input.SetString(ViewState[vProductOrder]) != "")
            {
                strWhere = Input.SetString(ViewState[vProductOrder]);
            }
            int count = 0;
            DataSet ds = new BLLProductOrder().GetList(Pager.PageSize, Pager.CurrentPageIndex, strWhere, ref count);
            Pager.RecordCount = count;
            this.gvList.DataSource = ds;
            this.gvList.DataBind();
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            this.Bind_gvList();
        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string eName = Input.SetString(e.CommandName);
            int orderID = Input.SetInt(e.CommandArgument);
            switch (eName.ToLower())
            {
                case "view":
                    Bind_View(orderID);
                    break;
                case "del":
                    this.Bind_Delete(orderID);
                    break;
            }
        }

        private void Bind_View(int id)
        {
            this.MultiViewList.ActiveViewIndex = 1;

            m_productorder = new BLLProductOrder().GetModel(id);

            BLLProductOrder b_ProductOrder = new BLLProductOrder();
            this.lblSendStatus.Text = b_ProductOrder.Get_Sendment(m_productorder.ShippingType);
            this.lblPayStauts.Text = b_ProductOrder.Get_Payment(m_productorder.PaymentType);
        }

        private void Bind_Delete(int id)
        {
            new BLLProductOrder().Delete(id);
            this.Bind_gvList();
        }

        public void Bind_OrderProduct(string OrderNum)
        {
            this.rpProductList.DataSource = new BLLProductOrderProduct().GetList(0, " OrderNum='" + Utils.FilterInjection(OrderNum) + "' ", " ID Desc");
            this.rpProductList.DataBind();
        }

        ///// <summary>
        ///// 获取用户信息
        ///// </summary>
        ///// <param name="oUserID"></param>
        ///// <returns></returns>
        //public ModelUser Get_User(object oUserID)
        //{
        //    int iUserID = Input.SetInt(oUserID);
        //    return new BLLUser().GetModel(iUserID);
        //}

        /// <summary>
        /// 获取支付方式
        /// </summary>
        /// <param name="oID"></param>
        /// <returns></returns>
        public string Get_ProductOrder_Pay(object oID)
        {
            int iID = Input.SetInt(oID);
            return new BLLProductOrder().Get_Payment(iID);
        }
        /// <summary>
        /// 获取发货方式
        /// </summary>
        /// <param name="oID"></param>
        /// <returns></returns>
        public string Get_ProductOrder_Send(object oID)
        {
            int iID = Input.SetInt(oID);
            return new BLLProductOrder().Get_Sendment(iID);
        }
    }
}
